package com.hyh.speex;

/**
 * Created by Administrator on 2018/11/20.
 */

public class Speex {



    /* quality
	 * 1 : 4kbps (very noticeable artifacts, usually intelligible)
	 * 2 : 6kbps (very noticeable artifacts, good intelligibility)
	 * 4 : 8kbps (noticeable artifacts sometimes)
	 * 6 : 11kpbs (artifacts usually only noticeable with headphones)
	 * 8 : 15kbps (artifacts not usually noticeable)
	 */
    private static final int DEFAULT_COMPRESSION = 5;

    private static Speex speex;
    private Speex(){
        init();
    }
    public static synchronized Speex getInstance(){
        if(speex==null){
            speex = new Speex();
        }
        return speex;
    }

    private void init() {
        load();
        open(DEFAULT_COMPRESSION);
    }

    private void load() {
        try {
            System.loadLibrary("native-lib");
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }

    private native int open(int quality);//设置压缩率
    public native int encode(short lin[],int offset,byte encoded[],int size);//编码
    public native int decode(byte encoded[],short lin[],int size);//解码
    public native int playback(short echoFrame[]);//采集播放声音用于回声消除
    public native int capture(short inputFrame[],short outFrame[]);//消除回音
    public native int echoCancel(short lin[],short echo[],short out[]);//回声消除
    public native int getFrameSize();//获取帧的长度
    public native int close();//关闭
}
